/*
 * @Author: chen17
 * @Date: 2022-06-01 13:53:52
 * @LastEditTime: 2022-10-12 10:59:00
 * @Description: 上传公用参数
 */

import { mapGetters, mapActions } from 'vuex'
import { domain, qiniuUrl } from '@/config/request'

export default {
    computed: {
        ...mapGetters(['uploadToken']),
        // 上传参数
        uploadData() {
            return {
                key: '',
                token: this.uploadToken
            }
        }
    },
    data() {
        return {
            domain,
            qiniuUrl
        }
    },
    methods: {
        ...mapActions('upload', ['initUploadToken', 'removeUploadToken']),
        // 定时5分钟重新获取token
        setTaskToUpdateToken() {
            let timer = setInterval(() => {
                this.getUploadToken()
            }, 1000 * 60 * 5)
            // 清除定时器
            this.$once('hook:beforeDestroy', () => {
                clearInterval(timer)
            })
        }
    },
    async mounted() {
        await this.initUploadToken()
    },
    destroyed() {
        this.removeUploadToken()
    }
}
